'\" te
.\" Copyright (c) 2007 Sun Microsystems, Inc. - All Rights Reserved.
.\" Copyright 1989 AT&T
.\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH READONLY 1 "April 9, 2016"
.SH NAME
readonly \- shell built-in function to protect the value of the given variable
from reassignment
.SH SYNOPSIS
.SS "sh"
.LP
.nf
\fBreadonly\fR [\fIname\fR]...
.fi

.SS "ksh"
.LP
.nf
\fB**readonly\fR [\fIname\fR [= \fIvalue\fR]]...
.fi

.LP
.nf
\fB**readonly\fR \fB-p\fR
.fi

.SS "ksh93"
.LP
.nf
\fB++readonly\fR [\fB-p\fR] [\fIname\fR [= \fIvalue\fR]]...
.fi

.SH DESCRIPTION
.SS "sh"
.LP
The given \fIname\fRs are marked \fBreadonly\fR and the values of these
\fIname\fRs may not be changed by subsequent assignment. If no arguments are
given, a list of all \fBreadonly\fR names is printed.
.SS "ksh"
.LP
The given \fIname\fRs are marked \fBreadonly\fR and these names cannot be
changed by subsequent assignment.
.sp
.LP
When \fB-p\fR is specified, \fBreadonly\fR writes to the standard output the
names and values of all read-only variables, in the following format:
.sp
.in +2
.nf
"readonly %s=%s\en", \fIname\fR, \fIvalue\fR
.fi
.in -2
.sp

.sp
.LP
if \fIname\fR is set, and:
.sp
.in +2
.nf
"readonly $s\en", \fIname\fR
.fi
.in -2
.sp

.sp
.LP
if \fIname\fR is unset.
.sp
.LP
The shell formats the output, including the proper use of quoting, so that it
is suitable for reinput to the shell as commands that achieve the same value
and \fBreadonly\fR attribute-setting results in a shell execution environment
in which:
.RS +4
.TP
1.
Variables with values set at the time they were output do not have the
\fBreadonly\fR attribute set.
.RE
.RS +4
.TP
2.
Variables that were unset at the time they were output do not have a value
at the time at which the saved output is re-input to the shell.
.RE
.sp
.LP
On this manual page, \fBksh\fR(1) commands that are preceded by one or two
\fB**\fR (asterisks) are treated specially in the following ways:
.RS +4
.TP
1.
Variable assignment lists preceding the command remain in effect when the
command completes.
.RE
.RS +4
.TP
2.
I/O redirections are processed after variable assignments.
.RE
.RS +4
.TP
3.
Errors cause a script that contains them to abort.
.RE
.RS +4
.TP
4.
Words, following a command preceded by \fB**\fR that are in the format of a
variable assignment, are expanded with the same rules as a variable assignment.
This means that tilde substitution is performed after the \fB=\fR sign and word
splitting and file name generation are not performed.
.RE
.SS "ksh93"
.LP
\fBreadonly\fR sets the \fBreadonly\fR attribute on each of the variables
specified by name which prevents their values from being changed. If
\fB=\fR\fIvalue\fR is specified, the variable name is set to \fIvalue\fR before
the variable is made \fBreadonly\fR.
.sp
.LP
If no names are specified then the names and values of all \fBreadonly\fR
variables are written to standard output.
.sp
.LP
\fBreadonly\fR is built-in to the shell as a declaration command so that field
splitting and pathname expansion are not performed on the arguments. Tilde
expansion occurs on value.
.sp
.ne 2
.na
\fB\fB-p\fR\fR
.ad
.RS 6n
Causes the output to be in a form of \fBreadonly\fR commands that can be used
as input to the shell to recreate the current set of \fBreadonly\fR variables.
.RE

.sp
.LP
On this manual page, \fBksh93\fR(1) commands that are preceded by one or two
\fB+\fR symbols are treated specially in the following ways:
.RS +4
.TP
1.
Variable assignment lists preceding the command remain in effect when the
command completes.
.RE
.RS +4
.TP
2.
I/O redirections are processed after variable assignments.
.RE
.RS +4
.TP
3.
Errors cause a script that contains them to abort.
.RE
.RS +4
.TP
4.
They are not valid function names.
.RE
.RS +4
.TP
5.
Words, following a command preceded by \fB++\fR that are in the format of a
variable assignment, are expanded with the same rules as a variable assignment.
This means that tilde substitution is performed after the \fB=\fR sign and
field splitting and file name generation are not performed.
.RE
.SH EXIT STATUS
.SS "ksh93"
.LP
The following exit values are returned:
.sp
.ne 2
.na
\fB\fB0\fR\fR
.ad
.RS 6n
Successful completion.
.RE

.sp
.ne 2
.na
\fB\fB>0\fR\fR
.ad
.RS 6n
An error occurred.
.RE

.SH SEE ALSO
.LP
.BR ksh (1),
.BR ksh93 (1),
.BR sh (1),
.BR typeset (1),
.BR attributes (7)
